package net.jeeshop.web.action.front.dsmd;

import net.jeeshop.core.Services;
import net.jeeshop.services.common.DsmdDesigner;
import net.jeeshop.services.front.dsmdAppointment.bean.DsmdAppointment;
import net.jeeshop.services.front.dsmdDesigner.DsmdDesignerService;
import net.jeeshop.web.action.front.FrontBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zuohao on 16/8/5.
 */

@Controller("frontDsmdDesignerAction")
@RequestMapping("dsmdDesigner")
public class DsmdDesignerAction extends FrontBaseController<DsmdDesigner> {
    @Override
    public Services<DsmdDesigner> getService() {
        return null;
    }

    @Autowired
    private DsmdDesignerService dsmdDesignerService;

    @RequestMapping("getDsmdDesignerListByType")
    @ResponseBody
    public Map<Object, Object> getDsmdDesignerListByType(@RequestParam("type") String type,@RequestParam("offset")Integer offset,@RequestParam("rows")Integer rows){
        Map<Object,Object> result=new HashMap<Object, Object>();
        List<DsmdDesigner> dsmdDesignerList=dsmdDesignerService.getDsmdDesignerListByType(type,offset,rows);
        for (DsmdDesigner dsmdDesigner:dsmdDesignerList){
            dsmdDesigner.setDesignerimage(systemManager.getSystemSetting().getImageRootPath()+dsmdDesigner.getDesignerimage());
        }
        int count=dsmdDesignerService.getDsmdDesignerCountByType(type);
        result.put("dsmdDesignerList",dsmdDesignerList);
        result.put("count",count);
        return result;
    }

    @RequestMapping("getDsmdDesignerDetialById")
    @ResponseBody
    public Map<String,Object> getDsmdDesignerDetialById(@RequestParam("id")String id){
        Map<String,Object> result=new HashMap<String, Object>();
        DsmdDesigner dsmdDesigner=dsmdDesignerService.selectById(id);
        List<String> worksImgList=new ArrayList<String>();
        for (String img:dsmdDesigner.getDesignerworks().split(",")){
            worksImgList.add(systemManager.getSystemSetting().getImageRootPath() + img);
        }
        dsmdDesigner.setDesignerimage(systemManager.getSystemSetting().getImageRootPath()+dsmdDesigner.getDesignerimage());
        result.put("dsmdDesigner", dsmdDesigner);
        result.put("worksImgList", worksImgList);
        return result;
    }

    //预约
    @RequestMapping("designerAppointment")
    @ResponseBody
    public Map<String, Object> designerAppointment(@RequestParam(value = "name",required = false) String name, @RequestParam(value="address",required = false) String address,
                                                   @RequestParam(value = "phone",required = false) String phone,  @RequestParam(value="email",required = false) String email,
                                                   @RequestParam(value = "age",required = false) String age, @RequestParam(value="profession",required = false) String profession,
                                                   @RequestParam(value = "sex",required = false) String sex, @RequestParam(value="high",required = false) String high,
                                                   @RequestParam(value = "weight",required = false) String weight, @RequestParam(value="chest",required = false) String chest,
                                                   @RequestParam(value = "waistline",required = false) String waistline, @RequestParam(value="buttocks",required = false) String buttocks,
                                                   @RequestParam(value = "arm",required = false) String arm, @RequestParam(value="trousers",required = false) String trousers,
                                                   @RequestParam(value = "shoulder",required = false) String shoulder, @RequestParam(value="neck",required = false) String neck,
                                                   @RequestParam(value = "special",required = false) String special,@RequestParam(value = "designerId")String designerId) {
        Map<String, Object> result = new HashMap<String, Object>();
        DsmdAppointment dsmdAppointment=new DsmdAppointment();
        dsmdAppointment.setName(name);
        dsmdAppointment.setAddress(address);
        dsmdAppointment.setPhone(phone);
        dsmdAppointment.setEmail(email);
        dsmdAppointment.setAge(age);
        dsmdAppointment.setProfession(profession);
        dsmdAppointment.setSex(sex);
        dsmdAppointment.setHigh(high);
        dsmdAppointment.setWeight(weight);
        dsmdAppointment.setChest(chest);
        dsmdAppointment.setWaistline(waistline);
        dsmdAppointment.setButtocks(buttocks);
        dsmdAppointment.setArm(arm);
        dsmdAppointment.setTrousers(trousers);
        dsmdAppointment.setShoulder(shoulder);
        dsmdAppointment.setNeck(neck);
        dsmdAppointment.setSpecial(special);
        dsmdAppointment.setDesignerId(designerId);
        dsmdDesignerService.insertDsmdAppointment(dsmdAppointment);
        result.put("code", "000000");
        result.put("msg", "OK");
        return result;
    }
}
